export function strToDate(val) {
    var dateString = val;
    var pattern = /(\d{4})(\d{2})(\d{2})/;
    var formatedDate = dateString.replace(pattern, '$1-$2-$3');
    var date = new Date(formatedDate);
    return date;
}

function contrastDate(refer) {
    if (!refer) return;
    let res = strToDate(refer)
    let currDate = new Date().getTime();
    let referDate = new Date(res).getTime();
    return currDate > referDate;
}


export function validateDate(startDate, endDate) {
    /**
     * 0    为开始
     * 1    进行中
     * 2    已过期
     */
    return contrastDate(startDate) && !contrastDate(endDate) ? '1'
        : !contrastDate(startDate) ? '0'
            : contrastDate(startDate) && contrastDate(endDate) ? '2' : ''
}

export function emptyObject(obj) {
    return Object.getOwnPropertyNames(obj).length > 0;
}